/**
 * Created by jiachneyu on 2018/3/29.
 */
const fs = require('fs');

function update() {
    let config = fs.readFileSync('/Users/jiachneyu/blog/message/config.js','utf-8');
    const regx = /devUrl: (.*)/g;
    config = config.replace(regx, `devUrl: 'http://${ip()}:3000'`);
    fs.writeFileSync('/Users/jiachneyu/blog/message/config.js',config,'utf-8')
}

function ip() {
    let interfaces = require('os').networkInterfaces();
    for(let devName in interfaces){
        let iface = interfaces[devName];
        for(let i=0;i<iface.length;i++){
            let alias = iface[i];
            if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
                return alias.address;
            }
        }
    }
}

module.exports = update;